{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2cb2a0b3-41a3-46b1-84d8-a6be2c7b3b7d",
   "metadata": {},
   "source": [
    "# `geom_band()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c3fd1873-c8be-4090-be03-8e313bae89e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"vuyunO\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v4.4.0/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"vuyunO\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"vuyunO\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "            <div id=\"kotlin_out_0\"></div>\n",
       "            <script type=\"text/javascript\">\n",
       "                            if(!window.kotlinQueues) {\n",
       "                window.kotlinQueues = {};\n",
       "            }\n",
       "            if(!window.kotlinQueues[\"DataFrame\"]) {\n",
       "                var resQueue = [];\n",
       "                window.kotlinQueues[\"DataFrame\"] = resQueue;\n",
       "                window[\"call_DataFrame\"] = function(f) {\n",
       "                    resQueue.push(f);\n",
       "                }\n",
       "            }\n",
       "            (function (){\n",
       "                var modifiers = [(function(script) {\n",
       "    script.src = \"https://cdn.jsdelivr.net/gh/Kotlin/dataframe@3db46ccccaa1291c0627307d64133317f545e6ae/core/src/main/resources/init.js\"\n",
       "    script.type = \"text/javascript\";\n",
       "})];\n",
       "                var e = document.getElementById(\"kotlin_out_0\");\n",
       "                modifiers.forEach(function (gen) {\n",
       "                    var script = document.createElement(\"script\");\n",
       "                    gen(script)\n",
       "                    script.addEventListener(\"load\", function() {\n",
       "                        window[\"call_DataFrame\"] = function(f) {f();};\n",
       "                        window.kotlinQueues[\"DataFrame\"].forEach(function(f) {f();});\n",
       "                        window.kotlinQueues[\"DataFrame\"] = [];\n",
       "                    }, false);\n",
       "                    script.addEventListener(\"error\", function() {\n",
       "                        window[\"call_DataFrame\"] = function(f) {};\n",
       "                        window.kotlinQueues[\"DataFrame\"] = [];\n",
       "                        var div = document.createElement(\"div\");\n",
       "                        div.style.color = 'darkred';\n",
       "                        div.textContent = 'Error loading resource DataFrame';\n",
       "                        document.getElementById(\"kotlin_out_0\").appendChild(div);\n",
       "                    }, false);\n",
       "                    \n",
       "                    e.appendChild(script);\n",
       "                });\n",
       "            })();\n",
       "            </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "                <style>\n",
       "                :root {\n",
       "    --background: #fff;\n",
       "    --background-odd: #f5f5f5;\n",
       "    --background-hover: #d9edfd;\n",
       "    --header-text-color: #474747;\n",
       "    --text-color: #848484;\n",
       "    --text-color-dark: #000;\n",
       "    --text-color-medium: #737373;\n",
       "    --text-color-pale: #b3b3b3;\n",
       "    --inner-border-color: #aaa;\n",
       "    --bold-border-color: #000;\n",
       "    --link-color: #296eaa;\n",
       "    --link-color-pale: #296eaa;\n",
       "    --link-hover: #1a466c;\n",
       "}\n",
       "\n",
       ":root[theme=\"dark\"], :root [data-jp-theme-light=\"false\"], .dataframe_dark{\n",
       "    --background: #303030;\n",
       "    --background-odd: #3c3c3c;\n",
       "    --background-hover: #464646;\n",
       "    --header-text-color: #dddddd;\n",
       "    --text-color: #b3b3b3;\n",
       "    --text-color-dark: #dddddd;\n",
       "    --text-color-medium: #b2b2b2;\n",
       "    --text-color-pale: #737373;\n",
       "    --inner-border-color: #707070;\n",
       "    --bold-border-color: #777777;\n",
       "    --link-color: #008dc0;\n",
       "    --link-color-pale: #97e1fb;\n",
       "    --link-hover: #00688e;\n",
       "}\n",
       "\n",
       "p.dataframe_description {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe {\n",
       "    font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n",
       "    font-size: 12px;\n",
       "    background-color: var(--background);\n",
       "    color: var(--text-color-dark);\n",
       "    border: none;\n",
       "    border-collapse: collapse;\n",
       "}\n",
       "\n",
       "table.dataframe th, td {\n",
       "    padding: 6px;\n",
       "    border: 1px solid transparent;\n",
       "    text-align: left;\n",
       "}\n",
       "\n",
       "table.dataframe th {\n",
       "    background-color: var(--background);\n",
       "    color: var(--header-text-color);\n",
       "}\n",
       "\n",
       "table.dataframe td {\n",
       "    vertical-align: top;\n",
       "}\n",
       "\n",
       "table.dataframe th.bottomBorder {\n",
       "    border-bottom-color: var(--bold-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(odd) {\n",
       "    background: var(--background-odd);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:nth-child(even) {\n",
       "    background: var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe tbody > tr:hover {\n",
       "    background: var(--background-hover);\n",
       "}\n",
       "\n",
       "table.dataframe a {\n",
       "    cursor: pointer;\n",
       "    color: var(--link-color);\n",
       "    text-decoration: none;\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover > td a {\n",
       "    color: var(--link-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe a:hover {\n",
       "    color: var(--link-hover);\n",
       "    text-decoration: underline;\n",
       "}\n",
       "\n",
       "table.dataframe img {\n",
       "    max-width: fit-content;\n",
       "}\n",
       "\n",
       "table.dataframe th.complex {\n",
       "    background-color: var(--background);\n",
       "    border: 1px solid var(--background);\n",
       "}\n",
       "\n",
       "table.dataframe .leftBorder {\n",
       "    border-left-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightBorder {\n",
       "    border-right-color: var(--inner-border-color);\n",
       "}\n",
       "\n",
       "table.dataframe .rightAlign {\n",
       "    text-align: right;\n",
       "}\n",
       "\n",
       "table.dataframe .expanderSvg {\n",
       "    width: 8px;\n",
       "    height: 8px;\n",
       "    margin-right: 3px;\n",
       "}\n",
       "\n",
       "table.dataframe .expander {\n",
       "    display: flex;\n",
       "    align-items: center;\n",
       "}\n",
       "\n",
       "/* formatting */\n",
       "\n",
       "table.dataframe .null {\n",
       "    color: var(--text-color-pale);\n",
       "}\n",
       "\n",
       "table.dataframe .structural {\n",
       "    color: var(--text-color-medium);\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .dataFrameCaption {\n",
       "    font-weight: bold;\n",
       "}\n",
       "\n",
       "table.dataframe .numbers {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe td:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "table.dataframe tr:hover .formatted .structural, .null {\n",
       "    color: var(--text-color-dark);\n",
       "}\n",
       "\n",
       "\n",
       "                </style>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a6ac8baf-2848-4b14-b43d-2ad7c162367e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Lets-Plot Kotlin API v.0.0.0-SNAPSHOT. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.4.0."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LetsPlot.getInfo()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee7c83f3-31e6-4a97-87f8-5519095c8c75",
   "metadata": {},
   "source": [
    "## Default"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2d3b2ca6-b8a7-45cb-8b5a-d1df13e12fe3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"MPNsZA\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"xmin\":-1.0,\n",
       "\"xmax\":1.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"MPNsZA\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot() + geomBand(xmin = -1, xmax = 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "045a3b81-ca53-4177-a4bd-af1e26ccffcb",
   "metadata": {},
   "source": [
    "## Both vertical and horizontal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "729c5583-5c4e-4c9b-bc95-45b1b67baae6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"nl435T\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xmin\",\n",
       "\"xmax\":\"xmax\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"data\":{\n",
       "\"xmin\":[-1.5,0.5],\n",
       "\"xmax\":[-0.5,1.5]\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"ymin\":\"ymin\",\n",
       "\"ymax\":\"ymax\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"data\":{\n",
       "\"ymin\":[-1.5,0.5],\n",
       "\"ymax\":[-0.5,1.5]\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"nl435T\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot() +\n",
    "    geomBand { xmin = listOf(-1.5, .5); xmax = listOf(-.5, 1.5) } +\n",
    "    geomBand { ymin = listOf(-1.5, .5); ymax = listOf(-.5, 1.5) }"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c89d5cd4-68aa-4e42-b554-e86033f1f661",
   "metadata": {},
   "source": [
    "## Additional parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c8a23db7-a4f3-4104-9470-e15029d54652",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"E6Ar10\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xmin\",\n",
       "\"xmax\":\"xmax\",\n",
       "\"fill\":\"fill\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":3.0,\n",
       "\"linetype\":\"dashed\",\n",
       "\"alpha\":0.5,\n",
       "\"show_legend\":false,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"data\":{\n",
       "\"xmin\":[-1.0,0.0],\n",
       "\"xmax\":[0.0,1.0],\n",
       "\"fill\":[\"a\",\"b\"]\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"E6Ar10\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot() +\n",
    "    geomBand(size = 3, alpha = 0.5, linetype = \"dashed\", showLegend = false)\n",
    "        { xmin = listOf(-1, 0); xmax = listOf(0, 1); fill = listOf(\"a\", \"b\") }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e2bd5bf4-7bc3-4728-ac47-61a76f2f0368",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"TSYMrc\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"fill\":\"x\"\n",
       "},\n",
       "\"stat\":\"boxplot\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"data\":{\n",
       "\"..middle..\":[2.0,5.0],\n",
       "\"..upper..\":[2.5,5.5],\n",
       "\"..ymax..\":[3.0,6.0],\n",
       "\"x\":[\"a\",\"b\"],\n",
       "\"..lower..\":[1.5,4.5],\n",
       "\"..ymin..\":[1.0,4.0]\n",
       "}\n",
       "}],\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"str\",\n",
       "\"column\":\"x\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"y\"\n",
       "}]\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"TSYMrc\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// stat\n",
    "\n",
    "letsPlot(mapOf(\n",
    "    \"x\" to listOf(\"a\", \"a\", \"a\", \"b\", \"b\", \"b\"),\n",
    "    \"y\" to listOf(1, 2, 3, 4, 5, 6)\n",
    ")) { x = \"x\"; y = \"y\" } + geomBand(stat = Stat.boxplot()) { fill = \"x\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4682c49c-4fcd-4da9-91a5-f56400939af3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"adyisX\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[-1.0,3.0]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xmin\",\n",
       "\"xmax\":\"xmax\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":{\n",
       "\"name\":\"nudge\",\n",
       "\"x\":1.0\n",
       "},\n",
       "\"geom\":\"band\",\n",
       "\"data\":{\n",
       "\"xmin\":[-1.0],\n",
       "\"xmax\":[1.0]\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"adyisX\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// position\n",
    "\n",
    "letsPlot() +\n",
    "    geomBand(position = positionNudge(x = 1)) { xmin = listOf(-1); xmax = listOf(1) } +\n",
    "    xlim(listOf(-1, 3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "903fa82a-efbe-4a82-9a73-a36063e4b372",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"AkJRPT\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xmin\",\n",
       "\"xmax\":\"xmax\",\n",
       "\"fill\":\"fill\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":0.0,\n",
       "\"sampling\":{\n",
       "\"n\":19.0,\n",
       "\"seed\":42.0,\n",
       "\"name\":\"random\"\n",
       "},\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"data\":{\n",
       "\"xmin\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,14.0,15.0,16.0,17.0,18.0,19.0],\n",
       "\"xmax\":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,15.0,16.0,17.0,18.0,19.0,20.0],\n",
       "\"fill\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,14.0,15.0,16.0,17.0,18.0,19.0]\n",
       "}\n",
       "}],\n",
       "\"computation_messages\":[\"sampling_random(n=19, seed=42) was applied to [band/identity stat] layer\"]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"AkJRPT\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// sampling\n",
    "\n",
    "val n = 20\n",
    "letsPlot() +\n",
    "    geomBand(size = 0, sampling = samplingRandom(n - 1, seed = 42)) {\n",
    "        xmin = (0 until n).toList()\n",
    "        xmax = (1..n).toList()\n",
    "        fill = (0 until n).toList()\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c6520f97-6792-489b-881e-4104705a2bf8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"rm9hsn\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"paint_a\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Set2\"\n",
       "},{\n",
       "\"aesthetic\":\"paint_b\",\n",
       "\"scale_mapper_kind\":\"color_brewer\",\n",
       "\"palette\":\"Pastel2\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xmin\",\n",
       "\"xmax\":\"xmax\",\n",
       "\"paint_a\":\"paint_a\",\n",
       "\"paint_b\":\"paint_b\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":1.5,\n",
       "\"color_by\":\"paint_a\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"fill_by\":\"paint_b\",\n",
       "\"data\":{\n",
       "\"xmin\":[-3.0,1.0],\n",
       "\"xmax\":[-1.0,3.0],\n",
       "\"paint_b\":[\"A\",\"B\"],\n",
       "\"paint_a\":[\"a\",\"b\"]\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"rm9hsn\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// colorBy/fillBy\n",
    "\n",
    "letsPlot() +\n",
    "    geomBand(colorBy = \"paint_a\", fillBy = \"paint_b\", size = 1.5) {\n",
    "        xmin = listOf(-3, 1)\n",
    "        xmax = listOf(-1, 3)\n",
    "        paint_a = listOf(\"a\", \"b\")\n",
    "        paint_b = listOf(\"A\", \"B\")\n",
    "    } +\n",
    "    scaleBrewer(\"paint_a\", palette = \"Set2\") +\n",
    "    scaleBrewer(\"paint_b\", palette = \"Pastel2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5292a9d4-75fd-49f3-be14-ac4981e09a0c",
   "metadata": {},
   "source": [
    "## Tooltips"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "defdaed4-7c5e-4c16-8cbf-863ed606d669",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"BvizOf\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":2,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"figures\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xstart\",\n",
       "\"xmax\":\"xend\"\n",
       "},\n",
       "\"data\":{\n",
       "\"color\":[\"black\",\"red\",\"blue\",\"green\",\"yellow\"],\n",
       "\"xstart\":[0.0,2.0,3.0,6.0,null],\n",
       "\"xend\":[1.0,4.0,5.0,7.0,null]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"identity\",\n",
       "\"guide\":\"none\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"fill\":\"color\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"alpha\":0.2,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xstart\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xend\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"yFrom\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"yTo\"\n",
       "},{\n",
       "\"type\":\"str\",\n",
       "\"column\":\"color\"\n",
       "}]\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"ymin\":\"yFrom\",\n",
       "\"ymax\":\"yTo\"\n",
       "},\n",
       "\"data\":{\n",
       "\"color\":[\"black\",\"red\",\"blue\",\"green\",\"yellow\"],\n",
       "\"yTo\":[0.0,-2.0,-3.0,null,-8.0],\n",
       "\"yFrom\":[-1.0,-4.0,-5.0,null,-9.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"fill\",\n",
       "\"scale_mapper_kind\":\"identity\",\n",
       "\"guide\":\"none\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"fill\":\"color\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"alpha\":0.2,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xstart\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xend\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"yFrom\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"yTo\"\n",
       "},{\n",
       "\"type\":\"str\",\n",
       "\"column\":\"color\"\n",
       "}]\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xstart\",\n",
       "\"xmax\":\"xend\"\n",
       "},\n",
       "\"data\":{\n",
       "\"xstart\":[0.0,2.0,3.0,6.0,null],\n",
       "\"xend\":[1.0,4.0,5.0,7.0,null]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"tooltips\":\"none\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xstart\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xend\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"yFrom\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"yTo\"\n",
       "},{\n",
       "\"type\":\"str\",\n",
       "\"column\":\"color\"\n",
       "}]\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xstart\",\n",
       "\"xmax\":\"xend\"\n",
       "},\n",
       "\"data\":{\n",
       "\"color\":[\"black\",\"red\",\"blue\",\"green\",\"yellow\"],\n",
       "\"xstart\":[0.0,2.0,3.0,6.0,null],\n",
       "\"xend\":[1.0,4.0,5.0,7.0,null]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"tooltips\":{\n",
       "\"lines\":[\"min|^xmin\",\"max|^xmax\",\"color|@color\"]\n",
       "},\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xstart\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xend\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"yFrom\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"yTo\"\n",
       "},{\n",
       "\"type\":\"str\",\n",
       "\"column\":\"color\"\n",
       "}]\n",
       "}\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"BvizOf\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val dataMap = mapOf(\n",
    "    \"xstart\" to listOf( 0,  2,  3,    6, null),\n",
    "    \"xend\" to   listOf( 1,  4,  5,    7, null),\n",
    "    \"yFrom\" to  listOf(-1, -4, -5, null,   -9),\n",
    "    \"yTo\" to    listOf( 0, -2, -3, null,   -8),\n",
    "    \"color\" to  listOf(\"black\", \"red\", \"blue\", \"green\", \"yellow\"),\n",
    ")\n",
    "\n",
    "val p1 = letsPlot(dataMap) { xmin = \"xstart\"; xmax = \"xend\" }\n",
    "val p2 = letsPlot(dataMap) { ymin = \"yFrom\"; ymax = \"yTo\" }\n",
    "\n",
    "gggrid(listOf(\n",
    "    p1 + geomBand(alpha = 0.2) { fill = \"color\" } + scaleFillIdentity(),\n",
    "    p2 + geomBand(alpha = 0.2) { fill = \"color\" } + scaleFillIdentity(),\n",
    "    p1 + geomBand(tooltips = tooltipsNone),\n",
    "    p1 + geomBand(tooltips = layerTooltips().line(\"min|^xmin\").line(\"max|^xmax\").line(\"color|@color\")),\n",
    "), ncol = 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "625b3638-fcfe-45c4-a7a8-d889d66e7cdf",
   "metadata": {},
   "source": [
    "## Different coordinate systems"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ad0074fc-2349-476c-ac81-54536a9bb884",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"798CqT\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":2,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"figures\":[{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"Default coord\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "\"ymin\":[-4.0,-1.0,3.0,null,null],\n",
       "\"xmin\":[-4.0,-2.5,-1.0,1.5,3.0],\n",
       "\"ymax\":[-3.0,1.0,4.0,null,null],\n",
       "\"xmax\":[-3.0,-1.5,1.0,2.5,4.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xmin\",\n",
       "\"xmax\":\"xmax\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":0.0,\n",
       "\"alpha\":0.2,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"fill\":\"red\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"ymin\":\"ymin\",\n",
       "\"ymax\":\"ymax\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":0.0,\n",
       "\"alpha\":0.2,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"fill\":\"blue\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xmin\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xmax\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"ymin\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"ymax\"\n",
       "}]\n",
       "}\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordFlip()\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"flip\",\n",
       "\"xlim\":[-4.25,4.25],\n",
       "\"flip\":true,\n",
       "\"ylim\":[-4.25,4.25]\n",
       "},\n",
       "\"data\":{\n",
       "\"ymin\":[-4.0,-1.0,3.0,null,null],\n",
       "\"xmin\":[-4.0,-2.5,-1.0,1.5,3.0],\n",
       "\"ymax\":[-3.0,1.0,4.0,null,null],\n",
       "\"xmax\":[-3.0,-1.5,1.0,2.5,4.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xmin\",\n",
       "\"xmax\":\"xmax\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":0.0,\n",
       "\"alpha\":0.2,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"fill\":\"red\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"ymin\":\"ymin\",\n",
       "\"ymax\":\"ymax\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":0.0,\n",
       "\"alpha\":0.2,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"fill\":\"blue\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xmin\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xmax\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"ymin\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"ymax\"\n",
       "}]\n",
       "}\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordFixed()\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"fixed\",\n",
       "\"xlim\":[-4.25,4.25],\n",
       "\"flip\":false,\n",
       "\"ylim\":[-4.25,4.25]\n",
       "},\n",
       "\"data\":{\n",
       "\"ymin\":[-4.0,-1.0,3.0,null,null],\n",
       "\"xmin\":[-4.0,-2.5,-1.0,1.5,3.0],\n",
       "\"ymax\":[-3.0,1.0,4.0,null,null],\n",
       "\"xmax\":[-3.0,-1.5,1.0,2.5,4.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xmin\",\n",
       "\"xmax\":\"xmax\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":0.0,\n",
       "\"alpha\":0.2,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"fill\":\"red\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"ymin\":\"ymin\",\n",
       "\"ymax\":\"ymax\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":0.0,\n",
       "\"alpha\":0.2,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"fill\":\"blue\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xmin\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xmax\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"ymin\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"ymax\"\n",
       "}]\n",
       "}\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"coordPolar()\"\n",
       "},\n",
       "\"mapping\":{\n",
       "},\n",
       "\"coord\":{\n",
       "\"name\":\"polar\",\n",
       "\"xlim\":[-4.25,4.25],\n",
       "\"ylim\":[-4.25,4.25]\n",
       "},\n",
       "\"data\":{\n",
       "\"ymin\":[-4.0,-1.0,3.0,null,null],\n",
       "\"xmin\":[-4.0,-2.5,-1.0,1.5,3.0],\n",
       "\"ymax\":[-3.0,1.0,4.0,null,null],\n",
       "\"xmax\":[-3.0,-1.5,1.0,2.5,4.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"xmin\",\n",
       "\"xmax\":\"xmax\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":0.0,\n",
       "\"alpha\":0.2,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"fill\":\"red\",\n",
       "\"data\":{\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"ymin\":\"ymin\",\n",
       "\"ymax\":\"ymax\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"size\":0.0,\n",
       "\"alpha\":0.2,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"fill\":\"blue\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xmin\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"xmax\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"ymin\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"ymax\"\n",
       "}]\n",
       "}\n",
       "}],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"798CqT\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val limits = Pair(-4.25, 4.25)\n",
    "\n",
    "val p = letsPlot(mapOf(\n",
    "    \"xmin\" to listOf(-4, -2.5, -1,  1.5,    3),\n",
    "    \"xmax\" to listOf(-3, -1.5,  1,  2.5,    4),\n",
    "    \"ymin\" to listOf(-4, -1,    3, null, null),\n",
    "    \"ymax\" to listOf(-3,  1,    4, null, null),\n",
    ")) +\n",
    "    geomBand(alpha = 0.2, size = 0, fill = \"red\") { xmin = \"xmin\"; xmax = \"xmax\" } +\n",
    "    geomBand(alpha = 0.2, size = 0, fill = \"blue\") { ymin = \"ymin\"; ymax = \"ymax\" }\n",
    "\n",
    "gggrid(listOf(\n",
    "    p + ggtitle(\"Default coord\"),\n",
    "    p + coordFlip(xlim = limits, ylim = limits) + ggtitle(\"coordFlip()\"),\n",
    "    p + coordFixed(xlim = limits, ylim = limits) + ggtitle(\"coordFixed()\"),\n",
    "    p + coordPolar(xlim = limits, ylim = limits) + ggtitle(\"coordPolar()\")\n",
    "), ncol = 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "831dca91-769e-4f21-bcda-33c3667dcfb0",
   "metadata": {},
   "source": [
    "## More complex example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "868046ea-e5ce-4daa-b463-ec9df2488a96",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"TSQ1L9\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"ggsize\":{\n",
       "\"width\":1000.0,\n",
       "\"height\":200.0\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"x\",\n",
       "\"datetime\":true\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"trans\":\"log10\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"xmin\":\"start\",\n",
       "\"xmax\":\"end\",\n",
       "\"fill\":\"party\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"data\":{\n",
       "\"start\":[-5.348196E11,-2.823588E11,-1.928484E11,-2.9898E10,1.452348E11,2.225628E11,3.487932E11,6.01254E11,7.274844E11,9.799452E11,1.232406E12,1.4848668E12],\n",
       "\"end\":[-2.823588E11,-1.928484E11,-2.9898E10,1.452348E11,2.225628E11,3.487932E11,6.01254E11,7.274844E11,9.799452E11,1.232406E12,1.4848668E12,1.6110972E12],\n",
       "\"party\":[\"Republican\",\"Democratic\",\"Democratic\",\"Republican\",\"Republican\",\"Democratic\",\"Republican\",\"Republican\",\"Democratic\",\"Republican\",\"Democratic\",\"Republican\"]\n",
       "},\n",
       "\"size\":0.0,\n",
       "\"alpha\":0.4,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"band\",\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"str\",\n",
       "\"column\":\"name\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"start\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"end\"\n",
       "},{\n",
       "\"type\":\"str\",\n",
       "\"column\":\"party\"\n",
       "}]\n",
       "}\n",
       "},{\n",
       "\"mapping\":{\n",
       "\"x\":\"date\",\n",
       "\"y\":\"unemploy\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"data\":{\n",
       "\"date\":[-7.90596E10,-7.63812E10,-7.37028E10,-7.11108E10,-6.84324E10,-6.58404E10,-6.3162E10,-6.04836E10,-5.7978E10,-5.52996E10,-5.27076E10,-5.00292E10,-4.74372E10,-4.47588E10,-4.20804E10,-3.94884E10,-3.681E10,-3.4218E10,-3.15396E10,-2.88612E10,-2.6442E10,-2.37636E10,-2.11716E10,-1.84932E10,-1.59012E10,-1.32228E10,-1.05444E10,-7.9524E9,-5.274E9,-2.682E9,-3600000.0,2.6748E9,5.094E9,7.7724E9,1.03644E10,1.30428E10,1.56348E10,1.83132E10,2.09916E10,2.35836E10,2.6262E10,2.8854E10,3.15324E10,3.42108E10,3.663E10,3.93084E10,4.19004E10,4.45788E10,4.71708E10,4.98492E10,5.25276E10,5.51196E10,5.7798E10,6.039E10,6.30684E10,6.57468E10,6.82524E10,7.09308E10,7.35228E10,7.62012E10,7.87932E10,8.14716E10,8.415E10,8.6742E10,8.94204E10,9.20124E10,9.46908E10,9.73692E10,9.97884E10,1.024668E11,1.050588E11,1.077372E11,1.103292E11,1.130076E11,1.15686E11,1.18278E11,1.209564E11,1.235484E11,1.262268E11,1.289052E11,1.313244E11,1.340028E11,1.365948E11,1.392732E11,1.418652E11,1.445436E11,1.47222E11,1.49814E11,1.524924E11,1.550844E11,1.577628E11,1.604412E11,1.628604E11,1.655388E11,1.681308E11,1.708092E11,1.734012E11,1.760796E11,1.78758E11,1.8135E11,1.840284E11,1.866204E11,1.892988E11,1.919772E11,1.944828E11,1.971612E11,1.997532E11,2.024316E11,2.050236E11,2.07702E11,2.103804E11,2.129724E11,2.156508E11,2.182428E11,2.209212E11,2.235996E11,2.260188E11,2.286972E11,2.312892E11,2.339676E11,2.365596E11,2.39238E11,2.419164E11,2.445084E11,2.471868E11,2.497788E11,2.524572E11,2.551356E11,2.575548E11,2.602332E11,2.628252E11,2.655036E11,2.680956E11,2.70774E11,2.734524E11,2.760444E11,2.787228E11,2.813148E11,2.839932E11,2.866716E11,2.890908E11,2.917692E11,2.943612E11,2.970396E11,2.996316E11,3.0231E11,3.049884E11,3.075804E11,3.102588E11,3.128508E11,3.155292E11,3.182076E11,3.207132E11,3.233916E11,3.259836E11,3.28662E11,3.31254E11,3.339324E11,3.366108E11,3.392028E11,3.418812E11,3.444732E11,3.471516E11,3.4983E11,3.522492E11,3.549276E11,3.575196E11,3.60198E11,3.6279E11,3.654684E11,3.681468E11,3.707388E11,3.734172E11,3.760092E11,3.786876E11,3.81366E11,3.837852E11,3.864636E11,3.890556E11,3.91734E11,3.94326E11,3.970044E11,3.996828E11,4.022748E11,4.049532E11,4.075452E11,4.102236E11,4.12902E11,4.153212E11,4.17996E11,4.20588E11,4.232664E11,4.258584E11,4.285368E11,4.312152E11,4.338108E11,4.364892E11,4.390812E11,4.417596E11,4.44438E11,4.469436E11,4.496184E11,4.522104E11,4.548888E11,4.574808E11,4.601592E11,4.628376E11,4.654332E11,4.681116E11,4.707036E11,4.73382E11,4.760604E11,4.784796E11,4.811544E11,4.837464E11,4.864248E11,4.890168E11,4.916952E11,4.943736E11,4.969692E11,4.996476E11,5.022396E11,5.04918E11,5.075964E11,5.100156E11,5.126904E11,5.152824E11,5.179608E11,5.205528E11,5.232312E11,5.259096E11,5.285052E11,5.311836E11,5.337756E11,5.36454E11,5.391324E11,5.415516E11,5.442264E11,5.468184E11,5.494968E11,5.520888E11,5.547672E11,5.574456E11,5.600412E11,5.627196E11,5.653116E11,5.6799E11,5.706684E11,5.73174E11,5.758488E11,5.784408E11,5.811192E11,5.837112E11,5.863896E11,5.89068E11,5.916636E11,5.94342E11,5.96934E11,5.996124E11,6.022908E11,6.0471E11,6.073848E11,6.099768E11,6.126552E11,6.152472E11,6.179256E11,6.20604E11,6.231996E11,6.25878E11,6.2847E11,6.311484E11,6.338268E11,6.36246E11,6.389208E11,6.415128E11,6.441912E11,6.467832E11,6.494616E11,6.5214E11,6.547356E11,6.57414E11,6.60006E11,6.626844E11,6.653628E11,6.67782E11,6.704568E11,6.730488E11,6.757272E11,6.783192E11,6.809976E11,6.83676E11,6.862716E11,6.8895E11,6.91542E11,6.942204E11,6.968988E11,6.994044E11,7.020792E11,7.046712E11,7.073496E11,7.099416E11,7.1262E11,7.152984E11,7.17894E11,7.205724E11,7.231644E11,7.258428E11,7.285212E11,7.309404E11,7.336152E11,7.362072E11,7.388856E11,7.414776E11,7.44156E11,7.468344E11,7.4943E11,7.521084E11,7.547004E11,7.573788E11,7.600572E11,7.624764E11,7.651512E11,7.677432E11,7.704216E11,7.730136E11,7.75692E11,7.783704E11,7.80966E11,7.836444E11,7.862364E11,7.889148E11,7.915932E11,7.940124E11,7.966872E11,7.992792E11,8.019576E11,8.045496E11,8.07228E11,8.099064E11,8.12502E11,8.151804E11,8.177724E11,8.204508E11,8.231292E11,8.256348E11,8.283096E11,8.309016E11,8.3358E11,8.36172E11,8.388504E11,8.415288E11,8.441208E11,8.468028E11,8.493948E11,8.520732E11,8.547516E11,8.571708E11,8.598456E11,8.624376E11,8.65116E11,8.67708E11,8.703864E11,8.730648E11,8.756568E11,8.783388E11,8.809308E11,8.836092E11,8.862876E11,8.887068E11,8.913816E11,8.939736E11,8.96652E11,8.99244E11,9.019224E11,9.046008E11,9.071928E11,9.098748E11,9.124668E11,9.151452E11,9.178236E11,9.202428E11,9.229176E11,9.255096E11,9.28188E11,9.3078E11,9.334584E11,9.361368E11,9.387288E11,9.414108E11,9.440028E11,9.466812E11,9.493596E11,9.518652E11,9.5454E11,9.57132E11,9.598104E11,9.624024E11,9.650808E11,9.677592E11,9.703512E11,9.730332E11,9.756252E11,9.783036E11,9.80982E11,9.834012E11,9.86076E11,9.88668E11,9.913464E11,9.939384E11,9.966168E11,9.992952E11,1.0018872E12,1.0045692E12,1.0071612E12,1.0098396E12,1.012518E12,1.0149372E12,1.017612E12,1.020204E12,1.0228824E12,1.0254744E12,1.0281528E12,1.0308312E12,1.0334232E12,1.0361052E12,1.0386972E12,1.0413756E12,1.044054E12,1.0464732E12,1.049148E12,1.05174E12,1.0544184E12,1.0570104E12,1.0596888E12,1.0623672E12,1.0649592E12,1.0676412E12,1.0702332E12,1.0729116E12,1.07559E12,1.0780956E12,1.0807704E12,1.0833624E12,1.0860408E12,1.0886328E12,1.0913112E12,1.0939896E12,1.0965816E12,1.0992636E12,1.1018556E12,1.104534E12,1.1072124E12,1.1096316E12,1.1123064E12,1.1148984E12,1.1175768E12,1.1201688E12,1.1228472E12,1.1255256E12,1.1281176E12,1.1307996E12,1.1333916E12,1.13607E12,1.1387484E12,1.1411676E12,1.1438424E12,1.1464344E12,1.1491128E12,1.1517048E12,1.1543832E12,1.1570616E12,1.1596536E12,1.1623356E12,1.1649276E12,1.167606E12,1.1702844E12,1.1727036E12,1.1753784E12,1.1779704E12,1.1806488E12,1.1832408E12,1.1859192E12,1.1885976E12,1.1911896E12,1.1938716E12,1.1964636E12,1.199142E12,1.2018204E12,1.204326E12,1.2070008E12,1.2095928E12,1.2122712E12,1.2148632E12,1.2175416E12,1.22022E12,1.222812E12,1.225494E12,1.228086E12,1.2307644E12,1.2334428E12,1.235862E12,1.2385368E12,1.2411288E12,1.2438072E12,1.2463992E12,1.2490776E12,1.251756E12,1.254348E12,1.25703E12,1.259622E12,1.2623004E12,1.2649788E12,1.267398E12,1.2700728E12,1.2726648E12,1.2753432E12,1.2779352E12,1.2806136E12,1.283292E12,1.285884E12,1.288566E12,1.291158E12,1.2938364E12,1.2965148E12,1.298934E12,1.3016088E12,1.3042008E12,1.3068792E12,1.3094712E12,1.3121496E12,1.314828E12,1.31742E12,1.320102E12,1.322694E12,1.3253724E12,1.3280508E12,1.3305564E12,1.3332312E12,1.3358232E12,1.3385016E12,1.3410936E12,1.343772E12,1.3464504E12,1.3490424E12,1.3517244E12,1.3543164E12,1.3569948E12,1.3596732E12,1.3620924E12,1.3647672E12,1.3673592E12,1.3700376E12,1.3726296E12,1.375308E12,1.3779864E12,1.3805784E12,1.3832604E12,1.3858524E12,1.3885308E12,1.3912092E12,1.3936284E12,1.3963032E12,1.3988952E12,1.4015736E12,1.4041656E12,1.406844E12,1.4095224E12,1.4121144E12,1.4147964E12,1.4173884E12,1.4200668E12,1.4227452E12,1.4251644E12,1.4278392E12],\n",
       "\"unemploy\":[2944.0,2945.0,2958.0,3143.0,3066.0,3018.0,2878.0,3001.0,2877.0,2709.0,2740.0,2938.0,2883.0,2768.0,2686.0,2689.0,2715.0,2685.0,2718.0,2692.0,2712.0,2758.0,2713.0,2816.0,2868.0,2856.0,3040.0,3049.0,2856.0,2884.0,3201.0,3453.0,3635.0,3797.0,3919.0,4071.0,4175.0,4256.0,4456.0,4591.0,4898.0,5076.0,4986.0,4903.0,4987.0,4959.0,4996.0,4949.0,5035.0,5134.0,5042.0,4954.0,5161.0,5154.0,5019.0,4928.0,5038.0,4959.0,4922.0,4923.0,4913.0,4939.0,4849.0,4875.0,4602.0,4543.0,4326.0,4452.0,4394.0,4459.0,4329.0,4363.0,4305.0,4305.0,4350.0,4144.0,4396.0,4489.0,4644.0,4731.0,4634.0,4618.0,4705.0,4927.0,5063.0,5022.0,5437.0,5523.0,6140.0,6636.0,7501.0,7520.0,7978.0,8210.0,8433.0,8220.0,8127.0,7928.0,7923.0,7897.0,7794.0,7744.0,7534.0,7326.0,7230.0,7330.0,7053.0,7322.0,7490.0,7518.0,7380.0,7430.0,7620.0,7545.0,7280.0,7443.0,7307.0,7059.0,6911.0,7134.0,6829.0,6925.0,6751.0,6763.0,6815.0,6386.0,6489.0,6318.0,6337.0,6180.0,6127.0,6028.0,6309.0,6080.0,6125.0,5947.0,6077.0,6228.0,6109.0,6173.0,6109.0,6069.0,5840.0,5959.0,5996.0,6320.0,6190.0,6296.0,6238.0,6325.0,6683.0,6702.0,6729.0,7358.0,7984.0,8098.0,8363.0,8281.0,8021.0,8088.0,8023.0,7718.0,8071.0,8051.0,7982.0,7869.0,8174.0,8098.0,7863.0,8036.0,8230.0,8646.0,9029.0,9267.0,9397.0,9705.0,9895.0,10244.0,10335.0,10538.0,10849.0,10881.0,11217.0,11529.0,11938.0,12051.0,11534.0,11545.0,11408.0,11268.0,11154.0,11246.0,10548.0,10623.0,10282.0,9887.0,9499.0,9331.0,9008.0,8791.0,8746.0,8762.0,8456.0,8226.0,8537.0,8519.0,8367.0,8381.0,8198.0,8358.0,8423.0,8321.0,8339.0,8395.0,8302.0,8460.0,8513.0,8196.0,8248.0,8298.0,8128.0,8138.0,7795.0,8402.0,8383.0,8364.0,8439.0,8508.0,8319.0,8135.0,8310.0,8243.0,8159.0,7883.0,7892.0,7865.0,7862.0,7542.0,7574.0,7398.0,7268.0,7261.0,7102.0,7227.0,7035.0,6936.0,6953.0,6929.0,6876.0,6601.0,6779.0,6546.0,6605.0,6843.0,6604.0,6568.0,6537.0,6518.0,6682.0,6359.0,6205.0,6468.0,6375.0,6577.0,6495.0,6511.0,6590.0,6630.0,6725.0,6667.0,6752.0,6651.0,6598.0,6797.0,6742.0,6590.0,6922.0,7188.0,7368.0,7459.0,7764.0,7901.0,8015.0,8265.0,8586.0,8439.0,8736.0,8692.0,8586.0,8666.0,8722.0,8842.0,8931.0,9198.0,9283.0,9454.0,9460.0,9415.0,9744.0,10040.0,9850.0,9787.0,9781.0,9398.0,9565.0,9557.0,9325.0,9183.0,9056.0,9110.0,9149.0,9121.0,8930.0,8763.0,8714.0,8750.0,8542.0,8477.0,8630.0,8583.0,8470.0,8331.0,7915.0,7927.0,7946.0,7933.0,7734.0,7632.0,7375.0,7230.0,7375.0,7187.0,7153.0,7645.0,7430.0,7427.0,7527.0,7484.0,7478.0,7328.0,7426.0,7423.0,7491.0,7313.0,7318.0,7415.0,7423.0,7095.0,7337.0,6882.0,6979.0,7031.0,7236.0,7253.0,7158.0,7102.0,7000.0,6873.0,6655.0,6799.0,6655.0,6608.0,6656.0,6454.0,6308.0,6476.0,6368.0,6306.0,6422.0,5941.0,6047.0,6212.0,6259.0,6179.0,6300.0,6280.0,6100.0,6032.0,5976.0,6111.0,5783.0,6004.0,5796.0,5951.0,6025.0,5838.0,5915.0,5778.0,5716.0,5653.0,5708.0,5858.0,5733.0,5481.0,5758.0,5651.0,5747.0,5853.0,5625.0,5534.0,5639.0,5634.0,6023.0,6089.0,6141.0,6271.0,6226.0,6484.0,6583.0,7042.0,7142.0,7694.0,8003.0,8258.0,8182.0,8215.0,8304.0,8599.0,8399.0,8393.0,8390.0,8304.0,8251.0,8307.0,8520.0,8640.0,8520.0,8618.0,8588.0,8842.0,8957.0,9266.0,9011.0,8896.0,8921.0,8732.0,8576.0,8317.0,8370.0,8167.0,8491.0,8170.0,8212.0,8286.0,8136.0,7990.0,7927.0,8061.0,7932.0,7934.0,7784.0,7980.0,7737.0,7672.0,7651.0,7524.0,7406.0,7345.0,7553.0,7453.0,7566.0,7279.0,7064.0,7184.0,7072.0,7120.0,6980.0,7001.0,7175.0,7091.0,6847.0,6727.0,6872.0,6762.0,7116.0,6927.0,6731.0,6850.0,6766.0,6979.0,7149.0,7067.0,7170.0,7237.0,7240.0,7645.0,7685.0,7497.0,7822.0,7637.0,8395.0,8575.0,8937.0,9438.0,9494.0,10074.0,10538.0,11286.0,12058.0,12898.0,13426.0,13853.0,14499.0,14707.0,14601.0,14814.0,15009.0,15352.0,15219.0,15098.0,15046.0,15113.0,15202.0,15325.0,14849.0,14474.0,14512.0,14648.0,14579.0,14516.0,15081.0,14348.0,14013.0,13820.0,13737.0,13957.0,13855.0,13962.0,13763.0,13818.0,13948.0,13594.0,13302.0,13093.0,12797.0,12813.0,12713.0,12646.0,12660.0,12692.0,12656.0,12471.0,12115.0,12124.0,12005.0,12298.0,12471.0,11950.0,11689.0,11760.0,11654.0,11751.0,11335.0,11279.0,11270.0,11136.0,10787.0,10404.0,10202.0,10349.0,10380.0,9702.0,9859.0,9460.0,9608.0,9599.0,9262.0,8990.0,9090.0,8717.0,8903.0,8610.0,8504.0,8526.0]\n",
       "},\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"line\",\n",
       "\"data_meta\":{\n",
       "\"series_annotations\":[{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"rownames\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"date\"\n",
       "},{\n",
       "\"type\":\"float\",\n",
       "\"column\":\"pce\"\n",
       "},{\n",
       "\"type\":\"float\",\n",
       "\"column\":\"pop\"\n",
       "},{\n",
       "\"type\":\"float\",\n",
       "\"column\":\"psavert\"\n",
       "},{\n",
       "\"type\":\"float\",\n",
       "\"column\":\"uempmed\"\n",
       "},{\n",
       "\"type\":\"int\",\n",
       "\"column\":\"unemploy\"\n",
       "}]\n",
       "}\n",
       "}]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"TSQ1L9\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "// See: https://gadflyjl.org/stable/gallery/geometries/#[Geom.band](@ref),-[Geom.hband](@ref),-[Geom.vband](@ref)\n",
    "\n",
    "import kotlinx.datetime.*\n",
    "\n",
    "fun DataFrame<*>.parseDates(column: String): DataFrame<*> {\n",
    "    return this.convert(column).toLocalDateTime()\n",
    "               .convert(column).with { (it as LocalDateTime).toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds() }\n",
    "}\n",
    "\n",
    "val presidentialDf = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/presidential.csv\")\n",
    "    .parseDates(\"start\").parseDates(\"end\")\n",
    "val economicsDf = DataFrame.readCSV(\"https://vincentarelbundock.github.io/Rdatasets/csv/ggplot2/economics.csv\")\n",
    "    .parseDates(\"date\")\n",
    "\n",
    "letsPlot() +\n",
    "    geomBand(data = presidentialDf.toMap(), size = 0, alpha = 0.4) { xmin = \"start\"; xmax = \"end\"; fill = \"party\" } +\n",
    "    geomLine(data = economicsDf.toMap()) { x = \"date\"; y = \"unemploy\" } +\n",
    "    scaleXDateTime() + scaleYContinuous(trans = \"log10\") +\n",
    "    ggsize(1000, 200)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.9.23"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
